/*
 * Copyright (C) 2012-2013  Romain DUBOIS
 * 
 * This file is part of NeMoS - Network and Modular Software
 * 
 * NeMoS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * NeMoS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with NeMoS.  If not, see <http://www.gnu.org/licenses/>.
 */
package nemos.util.log.internal;

import nemos.util.osgi.FlexibleServiceTracker;

import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;

/**
 * LogMessage : The log message data class.
 * 
 * @author Romain DUBOIS
 */
public class LogMessage {

    /** The logging service reference */
    private final ServiceReference<?> mService;
    /** The message log level */
    private final int mLevel;
    /** The message to log */
    private final String mMessage;
    /** The exception to log */
    private final Throwable mException;

    /** The OSGi log service tracker */
    private final FlexibleServiceTracker<LogService, LogService> mTracker;

    /**
     * Constructor
     * 
     * @param pRef
     *            The logging service reference
     * @param pLevel
     *            The message log level
     * @param pMsg
     *            The message to log
     * @param pException
     *            The exception to log
     * @param pTracker
     *            The OSGi log service tracker
     */
    public LogMessage(final ServiceReference<?> pRef, final int pLevel, final String pMsg,
            final Throwable pException,
            final FlexibleServiceTracker<LogService, LogService> pTracker) {
        super();
        mService = pRef;
        mLevel = pLevel;
        mMessage = pMsg;
        mException = pException;
        mTracker = pTracker;
    }

    /**
     * Get the service.
     * 
     * @return The service
     */
    public ServiceReference<?> getService() {
        return mService;
    }

    /**
     * Get the level.
     * 
     * @return The level
     */
    public int getLevel() {
        return mLevel;
    }

    /**
     * Get the message.
     * 
     * @return The message
     */
    public String getMessage() {
        return mMessage;
    }

    /**
     * Get the exception.
     * 
     * @return The exception
     */
    public Throwable getException() {
        return mException;
    }

    /**
     * Get the OSGi log service.
     * 
     * @return The OSGi log service
     */
    public LogService getLogger() {
        return mTracker.getService();
    }
}
